package main;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class PicPush extends JFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JButton b_top;
	private JButton b_center;
	private JButton b_bottom;
	
	private JLabel l_top;
	private JLabel l_center;
	private JLabel l_bottom;
	
	private ImageIcon icon_top1;
	private ImageIcon icon_top2;
	private ImageIcon icon_top3;
	
	private ImageIcon icon_center1;
	private ImageIcon icon_center2;
	private ImageIcon icon_center3;

	private ImageIcon icon_bottom1;
	private ImageIcon icon_bottom2;
	private ImageIcon icon_bottom3;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new PicPush();
	}
	
	public PicPush(){
		initIcons();
		initItems();
		initHandler();
		initPicPush();
	}
	
	public void initPicPush(){
		setLayout(new GridLayout(3,2,1,1));
		setTitle("Drueck dein Bild");
		setSize(400,300);
		setLocation(400, 200);
		
		add(b_top);
		add(l_top);
		add(b_center);
		add(l_center);
		add(b_bottom);
		add(l_bottom);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	}
	
	public void initItems(){
		b_top = new JButton("Oben");
		b_center = new JButton("Mitte");
		b_bottom = new JButton("Unten");
		l_top = new JLabel(icon_top1);
		l_center = new JLabel(icon_center1);
		l_bottom = new JLabel(icon_bottom1);
	}
	
	public void initIcons(){
		icon_top1 = new ImageIcon("graphics/oben1.gif","oben1");
		icon_top2 = new ImageIcon("graphics/oben2.gif","oben2");
		icon_top3 = new ImageIcon("graphics/oben3.gif","oben3");
		
		icon_center1 = new ImageIcon("graphics/mitte1.gif","mitte1");
		icon_center2 = new ImageIcon("graphics/mitte2.gif","mitte2");
		icon_center3 = new ImageIcon("graphics/mitte3.gif","mitte3");
		
		icon_bottom1 = new ImageIcon("graphics/unten1.gif","unten1");
		icon_bottom2 = new ImageIcon("graphics/unten2.gif","unten2");
		icon_bottom3 = new ImageIcon("graphics/unten3.gif","unten3");
	}
	
	public void initHandler(){
		b_top.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				if(l_top.getIcon().equals(icon_top1)){
					l_top.setIcon(icon_top2);
				}else if(l_top.getIcon().equals(icon_top2)){
					l_top.setIcon(icon_top3);
				}else if(l_top.getIcon().equals(icon_top3)){
					l_top.setIcon(icon_top1);
				}
			}
		});
		
		b_center.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				if(l_center.getIcon().equals(icon_center1)){
					l_center.setIcon(icon_center2);
				}else if(l_center.getIcon().equals(icon_center2)){
					l_center.setIcon(icon_center3);
				}else if(l_center.getIcon().equals(icon_center3)){
					l_center.setIcon(icon_center1);
				}
			}
		});
		
		b_bottom.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				if(l_bottom.getIcon().equals(icon_bottom1)){
					l_bottom.setIcon(icon_bottom2);
				}else if(l_bottom.getIcon().equals(icon_bottom2)){
					l_bottom.setIcon(icon_bottom3);
				}else if(l_bottom.getIcon().equals(icon_bottom3)){
					l_bottom.setIcon(icon_bottom1);
				}
			}
		});
	}

}
